package com.example.demo.entity;

import sun.util.resources.cldr.ms.CurrencyNames_ms;

/**
 * 异常类封装
 */

public class CodeMsg {

    private int code;
    private String msg;

    public static CodeMsg SUCCESS=new CodeMsg(0,"success");
    public static CodeMsg SERVER_ERROR=new CodeMsg(500100,"服务端异常");
    public static CodeMsg BIND_ERROR=new CodeMsg(500101,"参数校验异常");
    public static CodeMsg ERROR=new CodeMsg(400,"error");
    public static CodeMsg NULL_ERROR=new CodeMsg(400,"用户密码或账号错误");

    public static CodeMsg EMAIL_HAVING=new CodeMsg(500,"用户已经提交过验证码请求");

    public static CodeMsg APPLY_ERROR=new CodeMsg(400,"用户提交申请失败");


    private CodeMsg(){

    }

    private CodeMsg(int code,String Msg){
        this.code = code;
        this.msg= Msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 下面是封装返回错误信息，不写只能获取无返回值
     */
    public CodeMsg fillArgs(Object... arg){
        int code=this.code;
        //将错误对象封装成字符串
        String message=String.format(this.msg);
        return new CodeMsg(code,message);
    }


    //重写返回信息体，不然用tostring无法返回字符信息，将上面信息封装返回,上面的信息可以直接通过用这个类然后直接用例如:（CodeMsg.SUCCESS）
    @Override
    public String toString(){
        return "CodeMsg[code="+code+",msg="+msg+"]";
    }

}
